var MyAjaxObj = new Object(); 
var maxXmlHttpCount = 5; //最多5个xmlhttp对象存在 
MyAjaxObj.reqList = []; //可以清空里面的项 


MyAjaxObj.getFreeObj = function() 
{ 
var req=null; 
var len =this.reqList.length; 
//先从当前的池里取 
for (var i = 0; i < len; i++) { 
if (this.reqList[i]) { 
if (this.reqList[i].readyState == 4 || this.reqList[i].readyState == 0) { 
req = this.reqList[i]; 
break; 
} 
} 
} 
//如果没有闲置的对象，自己独立创建 
if (req ==null) { 
if (this.reqList.length < maxXmlHttpCount) { 
req = CreateXmlarray(); 
this.reqList.push(req); 
} 
} 
return req; 
} 



MyAjaxObj.clearReqList = function() { 
var len = MyAjaxObj.reqList.length; 
for (var i = 0; i < len; i++) { 
var req = MyAjaxObj.reqList[i]; 
if (req) { 
try { 
delete req; 
} catch (e) 
{ } 
} 
} 
MyAjaxObj.reqList = []; 
} 
 


MyAjaxObj.send=function mysenddata(item,urlNEW,postdataNEW,wantoMD5new,suoyin) 
{ 
var req=this.getFreeObj();
var postdata="";
var wantoMD5="";
var url=urlNEW;
postdata=postdataNEW;
wantoMD5=wantoMD5new;      
wantoMD5+="utjvud6756-cjakfjl&*￥##";
 var hash=hex_md5(wantoMD5);
 postdata+="&sign="+ escape(hash);
	url+="?"+postdata;	 
	req.open("POST",url,false); 
	req.onreadystatechange =(function(){
if (req.readyState == 4) { 
if (req.status == 200) {  
	 var mytxt=req.responseText;	
     Callrighttablereturn(mytxt,suoyin); 
		} 
		}
	}); 
	req.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	req.send();
	MyAjaxObj.reqList.push(req); 
} 
	 
	 

MyAjaxObj.sendPOST=function mysenddata(item,urlNEW,postdataNEW,wantoMD5new,tblname) 
{ 
var req=this.getFreeObj();
var postdata="";
var wantoMD5="";
var url=urlNEW;
postdata=postdataNEW;
wantoMD5=wantoMD5new;      
wantoMD5+="utjvud6756-cjakfjl&*￥##";
 var hash=hex_md5(wantoMD5);
 postdata+="&sign="+ escape(hash);
	url+="?"+postdata;	 
	req.open("POST",url,false); 
	req.onreadystatechange =(function(){
if (req.readyState == 4) { 
if (req.status == 200) {  
	 var mytxt=req.responseText;	
	 CallPosteditreturn(mytxt,tblname);	 
		} 
		}
	}); 
	req.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	req.send();
	MyAjaxObj.reqList.push(req); 
} 
	 
	 
	 
	
function sendGETright(indexi)
{ 

var tempxml=xmlARRAY[indexi];
var tablename=tempxml[0];
var url=tempxml[2];
var username=sessionStorage.getItem('username');
var company_id=sessionStorage.getItem('company_id');
var token=sessionStorage.getItem('token');
if (typeof(token)=="undefined" || token=="" || token==null)
{
zhuxiaonoquery();
window.location = "/index.html";
return;
}
var postdata="";
var wantoMD5new="";
var method="POST";
if (url=="")
{
 url="/poscloud/v1/shop/config/getcomma";
  postdata="company_id="+escape(company_id)+"&token="+escape(token)+"&type="+escape(tablename)+"&username="+escape(username);
  wantoMD5new="company_id="+escape(company_id)+"token="+escape(token)+"type="+escape(tablename)+"username="+escape(username);
 }
MyAjaxObj.send("form1",url,postdata,wantoMD5new,indexi);   
}



function sendGETallTable(tblname,gore,filter_where)
{ 
var indexi=getGloble_arrayindex(tblname);
var biaozhiFLG=Globle_array[indexi][3];
var tablename=tblname;
var url="";
//获取添加或修改的HTML源码
if (gore=="e")
url=Globle_array[indexi][6];
else
url="";
var filt="";
var filtesc="";
if (filter_where!="")
{
filt="&zfilter_where="+escape(filter_where)
filtesc="zfilter_where="+escape(filter_where)
}


var username=sessionStorage.getItem('username');
var company_id=sessionStorage.getItem('company_id');
var token=sessionStorage.getItem('token');
if (typeof(token)=="undefined" || token=="" || token==null)
{
zhuxiaonoquery();
window.location = "/index.html";
return;
}
var postdata="";
var wantoMD5new="";
var method="POST";
if (url=="")
{
if (biaozhiFLG=="z")
 url="/poscloud/v1/companymanagement/config/get";
 else if (biaozhiFLG=="c")
 url="/poscloud/v1/company/config/get";
 else if (biaozhiFLG=="s")
 url="/poscloud/v1/shop/config/get";
 var op_shop_id= sessionStorage.getItem('shop_id');
  postdata="company_id="+escape(company_id)+"&op_shop_id="+escape(op_shop_id)+"&token="+escape(token)+"&type="+escape(tablename)+"&username="+escape(username)+filt;
  wantoMD5new="company_id="+escape(company_id)+"op_shop_id="+escape(op_shop_id)+"token="+escape(token)+"type="+escape(tablename)+"username="+escape(username)+filtesc;
 }
MyAjaxObj.send("form1",url,postdata,wantoMD5new,indexi);   
}




function sendAddDeleteEdit(tblname)
{ 
var indexi=getGloble_arrayindex(tblname);
var biaozhiFLG=Globle_array[indexi][3];
var tablename=tblname;
var url="";
var username=sessionStorage.getItem('username');
var company_id=sessionStorage.getItem('company_id');
var token=sessionStorage.getItem('token');
var op_shop_id=sessionStorage.getItem('shop_id');
if (typeof(token)=="undefined" || token=="" || token==null)
{
zhuxiaonoquery();
window.location = "/index.html";
return;
}
var oForm = document.forms["form1"]; 
var arrayINPUT=oForm.getElementsByTagName("input");
var aChoices = new Array(); 
a=new Array('username',username);
 aChoices.push(a);
a=new Array('company_id',company_id);
 aChoices.push(a);
a=new Array('token',token);
 aChoices.push(a);
a=new Array('op_shop_id',op_shop_id);
aChoices.push(a);

//如果是权限表
if (tblname=="user_right")
{
var rigth="[";
var cnt=0;
for (var i=0;i<arrayINPUT.length;i++) 
	   {
	   if (arrayINPUT[i].name=="right_name")
	   {
	   if (arrayINPUT[i].checked)
	   {
	   cnt++;
	   if (cnt==1)
	   rigth+=arrayINPUT[i].value;
	   else
	   rigth+=","+arrayINPUT[i].value;	   	   
	   }
	 	   
	   }
	   }
rigth+="]";
 a=new Array("right_name",rigth);
aChoices.push(a);
}

 for (var i=0;i<arrayINPUT.length;i++) 
	   {
	   if (arrayINPUT[i].name!="style" && arrayINPUT[i].name!="right_name")
	   {
	   a=new Array(arrayINPUT[i].name,arrayINPUT[i].value);
	   aChoices.push(a); 	   
	   }
	   }
aChoices.sort();	 
var postdata="";
var wantoMD5new="";
for (var m=0;m<aChoices.length;m++)	 
{
var n=aChoices[m][0];
var v=aChoices[m][1];
if (m==0)
postdata=n+"="+escape(v)
else
postdata+="&"+n+"="+escape(v)

 wantoMD5new+=n+"="+escape(v)
}
 
var method="POST";
if (biaozhiFLG=="z")
 url="/poscloud/v1/companymanagement/config/set";
 else if (biaozhiFLG=="c")
 url="/poscloud/v1/company/config/set";
 else if (biaozhiFLG=="r")
 url="/poscloud/v1/company/report/get";
 else if (biaozhiFLG=="s")
 url="/poscloud/v1/shop/config/set";
 MyAjaxObj.sendPOST("form1",url,postdata,wantoMD5new,tablename);   

}

 

function sendTODelete(tblname,cmd,config_table,where_name,where_value)
{ 
var indexi=getGloble_arrayindex(tblname);
var biaozhiFLG=Globle_array[indexi][3];
var tablename=tblname;
var url="";
var username=sessionStorage.getItem('username');
var company_id=sessionStorage.getItem('company_id');
var token=sessionStorage.getItem('token');
var op_shop_id=sessionStorage.getItem('shop_id');
if (typeof(token)=="undefined" || token=="" || token==null)
{
zhuxiaonoquery();
window.location = "/index.html";
return;
}
 

var aChoices = new Array(); 
a=new Array('username',username);
 aChoices.push(a);
a=new Array('company_id',company_id);
 aChoices.push(a);
a=new Array('token',token);
 aChoices.push(a);
a=new Array('op_shop_id',op_shop_id);
aChoices.push(a);
a=new Array('cmd',cmd);
aChoices.push(a);

a=new Array('config_table',config_table);
aChoices.push(a);

a=new Array('where_name',where_name);
aChoices.push(a);

a=new Array('where_value',where_value);
aChoices.push(a); 
aChoices.sort();	 
var postdata="";
var wantoMD5new="";
for (var m=0;m<aChoices.length;m++)	 
{
var n=aChoices[m][0];
var v=aChoices[m][1];
if (m==0)
postdata=n+"="+escape(v)
else
postdata+="&"+n+"="+escape(v)

 wantoMD5new+=n+"="+escape(v)
}
 
var method="POST";
if (biaozhiFLG=="z")
 url="/poscloud/v1/companymanagement/config/set";
 else if (biaozhiFLG=="c")
 url="/poscloud/v1/company/config/set";
 else if (biaozhiFLG=="s")
 url="/poscloud/v1/shop/config/set";
MyAjaxObj.sendPOST("form1",url,postdata,wantoMD5new,tablename);   
}





